package cc.rengu.redp.bizimpl.upmp.controller;

import cc.rengu.igas.bomp.facade.BompManualAdjustAcctService;
import cc.rengu.redp.bizimpl.upmp.domain.BManualAcctInfo;
import cc.rengu.redp.bizimpl.upmp.service.IBManualAcctInfoService;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author lizk
 */
@RestController
@Slf4j
@RequestMapping("/admin/upmp/bManualAcctInfo")
public class BManualAcctInfoController extends BaseController {

    @Autowired
    private IBManualAcctInfoService manualAcctInfoService;

    @DubboReference(version = "${dubbo.protocol.version}", check = false)
    private BompManualAdjustAcctService bompManualAdjustAcctService;

    @GetMapping
    public Map<String, Object> findByPage(QueryRequest queryRequest, BManualAcctInfo manualAcctInfo) {
        return getDataTable(manualAcctInfoService.findByPage(queryRequest, manualAcctInfo));
    }



    @PostMapping
    public OperationResult editSave(BManualAcctInfo entity) throws RedpException {

        OperationResult operationResult = manualAcctInfoService.saveData(entity);
        Map<String, Object> data = (Map) operationResult.getData();
        String status = (String) data.get("status");
        if ("true".equals(status)) {
            BManualAcctInfo bmanualacctinfo = (BManualAcctInfo) data.get("entity");
            manualAcctInfoService.manualPayment(bompManualAdjustAcctService, bmanualacctinfo);
        }
        return operationResult;
    }

    @GetMapping("/statusdetailPage")
    public Map<String, String> statusdetailPage(BManualAcctInfo entity) throws RedpException {
       return manualAcctInfoService.manualAccoutingStatusQuery(entity, bompManualAdjustAcctService);
    }

}
